package com.zlyx.easy.core.tool;

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;

public final class Json {

	private static ObjectMapper mapper;

	public static ObjectMapper mapper() {
		if (mapper == null) {
			mapper = new ObjectMapper();
		}
		return mapper;
	}

	public static ObjectWriter pretty() {
		return mapper().writer(new DefaultPrettyPrinter());
	}

	public static String pretty(Object o) {
		try {
			return pretty().writeValueAsString(o);
		} catch (Exception e) {
			return null;
		}
	}
}